package com.yuejian_06.yuejian_06.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.squareup.picasso.Picasso;
import com.yuejian_06.yuejian_06.Listener.MeListener;
import com.yuejian_06.yuejian_06.R;
import com.yuejian_06.yuejian_06.bean.ActivityBean;
import com.yuejian_06.yuejian_06.bean.PicBean;
import com.yuejian_06.yuejian_06.model.HomeModel;
import com.yuejian_06.yuejian_06.model.PicModel;

public class AcInfoActivity extends BaseActivity {
    private TextView activity_name,activity_address,activity_date,activity_price,activity_phone,activity_content;
    private Button sign;
    private ImageView activity_pic;
    private String activity_id;
    private ImageButton back;

    @Override
    void initViews() {

    }

    @Override
    void initEvents() {

    }

    @Override
    void initData() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ac_info);
        initView();//初始化事件
        Intent intent = getIntent();
        activity_id = intent.getStringExtra("activity_id");
        HomeModel homeModel = new HomeModel();
        homeModel.getActivityInfo(activity_id,meListener);
    }

    private  void initView(){
        activity_name = (TextView) findViewById(R.id.activity_name);
        activity_address = (TextView) findViewById(R.id.activity_address);
        activity_date = (TextView) findViewById(R.id.activity_date);
        activity_price = (TextView) findViewById(R.id.activity_price);
        activity_phone = (TextView) findViewById(R.id.activity_phone);
        activity_content = (TextView) findViewById(R.id.activity_content);
        activity_pic = (ImageView) findViewById(R.id.activity_pic);
        back = (ImageButton) findViewById(R.id.back);
        sign = (Button) findViewById(R.id.sign);

        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        sign.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(AcInfoActivity.this,SignActivity.class);
                intent.putExtra("activity_id",activity_id);
                intent.putExtra("activity_price",activity_price+"");
                intent.putExtra("activity_name",activity_name+"");
                startActivityForResult(intent,1);
            }
        });
    }

    private MeListener<ActivityBean> meListener =new MeListener<ActivityBean>() {
        @Override
        public void onResponse(ActivityBean o) {
            ActivityBean res=o;
            activity_name.setText(res.getActivity_name());
            activity_address.setText("活动地址："+res.getActivity_address());
            activity_date.setText("活动日期："+res.getActivity_date());
            activity_price.setText("价格："+res.getActivity_price()+" 元/人");
            activity_phone.setText("联系电话："+res.getActivity_phone());
            activity_content.setText("    "+res.getActivity_content());
            if (!"".equals(res.getActivity_pic()))
                Picasso.with(AcInfoActivity.this).load("http://10.0.2.2/yuejian/Public/acpics/"+res.getActivity_pic()).into(activity_pic);
        }
        @Override
        public void onFail(String msg) {
            Toast.makeText(AcInfoActivity.this,"活动详情失败",Toast.LENGTH_SHORT).show();
        }
    };
}
